/**
 * Created by kamlyli on 2017/7/22.
 */

import NetUtil from '../utils/netUtil'
import Config from '../config'

export default class API {
  /**
   * 获取cookie
   */
  static getCookie (code, rawData, signature, encryptedData, iv) {
    return NetUtil.postJson({}, `${Config.HOST.AQ}webapp/cookie`, {code, rawData, signature, encryptedData, iv})
  }

  /**
   * 获取练习问题
   */
  static getPracticeProblem (cookie, type) {
    return NetUtil.getJson(cookie, `${Config.HOST.AQ}practice/question/${type}`, {})
  }

  /**
   * 回答练习问题
   */
  static answerPracticeProblem (cookie, type, id, answer) {
    return NetUtil.postJson(cookie, `${Config.HOST.AQ}practice/question/`, {type, id, answer})
  }

  /**
   * 收藏练习回答问题
   */
  static collectionPracticeProblem (cookie, id) {
    return NetUtil.postJson(cookie, `${Config.HOST.AQ}collection/question/`, {id})
  }

  /**
   * 获取收藏问题
   */
  static getCollectionProblem (cookie, type) {
    return NetUtil.getJson(cookie, `${Config.HOST.AQ}collection/question/`, {})
  }

  /**
   * 回答收藏问题
   */
  static answerCollectionProblem (cookie, id, answer) {
    return NetUtil.postJson(cookie, `${Config.HOST.AQ}collection/question/answer`, {id, answer})
  }

  /**
   * 删除收藏问题
   */
  static delCollectionProblem (cookie, id) {
    return NetUtil.delJson(cookie, `${Config.HOST.AQ}collection/question/${id}`, {})
  }

  /**
   * 获取测试确认
   */
  static getExamConfirm (cookie, type) {
    return NetUtil.getJson(cookie, `${Config.HOST.AQ}Exam/confirm/${type}`, {})
  }

  /**
   * 随机测试题目
   */
  static getExamRandom (cookie, type) {
    return NetUtil.getJson(cookie, `${Config.HOST.AQ}Exam/random/${type}`, {})
  }

  /**
   * 获取测试题目
   */
  static getExamQuestion (cookie, type) {
    return NetUtil.getJson(cookie, `${Config.HOST.AQ}Exam/question/${type}`, {})
  }

  /**
   * 回答测试题目
   */
  static answerExamQuestion (cookie, id, answer) {
    return NetUtil.postJson(cookie, `${Config.HOST.AQ}Exam/question/answer`, {id, answer})
  }

  /**
   * 提交测试题目
   */
  static submitExamQuestion (cookie, type) {
    return NetUtil.postJson(cookie, `${Config.HOST.AQ}Exam/question/${type}`, {})
  }

  /**
   * 获取错误问题
   */
  static getMistakeProblem (cookie, type) {
    return NetUtil.getJson(cookie, `${Config.HOST.AQ}Mistake/question/`, {})
  }

  /**
   * 回答错误问题
   */
  static answerMistakeProblem (cookie, id, answer) {
    return NetUtil.postJson(cookie, `${Config.HOST.AQ}Mistake/question/answer`, {id, answer})
  }

  /**
   * 删除错误问题
   */
  static delMistakeProblem (cookie, id) {
    return NetUtil.delJson(cookie, `${Config.HOST.AQ}Mistake/question/${id}`, {})
  }

  /**
   * 排行榜
   */
  static rankingIndex (cookie) {
    return NetUtil.getJson(cookie, `${Config.HOST.AQ}Ranking`, {})
  }
}
